//
//  GeoMetry.m
//  Trackit
//
//  Created by yaodaobin on 2017/4/18.
//  Copyright © 2017年 yaodaobin. All rights reserved.
//

#import "GeoMetry.h"

@implementation GeoMetry

- (instancetype)init {
    self = [super init];
    if (self) {
        self.coordinates = [NSMutableArray array];
    }
    return self;

}

- (instancetype)initWithDictionary:(NSDictionary *)dictionary {
    self = [super init];
    if (self) {
        self.type = [GeoMetry translateToGeometryType:[CommonFunction getValueFromDic:dictionary withKey:@"type"]];
        self.coordinates = [NSMutableArray arrayWithArray:dictionary[@"coordinates"]];
    }
    return self;
}

- (NSMutableArray *)coordinates {
    if (!_coordinates) {
        _coordinates = [NSMutableArray array];
    }
    return _coordinates;
}

+ (NSString *)translateToGeometryTypeString:(GeometryType)type {
    NSString *result = @"";
    switch (type) {
        case GeometryTypePositions:
            result = @"Positions";
            break;
        case GeometryTypePoint:
            result = @"Point";
            break;
        case GeometryTypeMultiPoint:
            result = @"MultiPoint";
            break;
        case GeometryTypeLineString:
            result = @"LineString";
            break;
        case GeometryTypeMultiLineString:
            result = @"MultiLineString";
            break;
        case GeometryTypePolygon:
            result = @"Polygon";
            break;
        case GeometryTypeMultiPolygon:
            result = @"MultiPolygon";
            break;
        case GeometryTypeGeometryCollection:
            result = @"GeometryCollection";
            break;
    }
    return result;
}

+ (GeometryType)translateToGeometryType:(NSString *)typeString {
    GeometryType type = GeometryTypePositions;
    if ([typeString isEqualToString:@"Positions"]) {
        type = GeometryTypePositions;
    } else if ([typeString isEqualToString:@"Point"]) {
        type = GeometryTypePoint;
    } else if ([typeString isEqualToString:@"MultiPoint"]) {
        type = GeometryTypeMultiPoint;
    } else if ([typeString isEqualToString:@"LineString"]) {
        type = GeometryTypeLineString;
    } else if ([typeString isEqualToString:@"MultiLineString"]) {
        type = GeometryTypeMultiLineString;
    } else if ([typeString isEqualToString:@"Polygon"]) {
        type = GeometryTypePolygon;
    } else if ([typeString isEqualToString:@"MultiPolygon"]) {
        type = GeometryTypeMultiPolygon;
    } else if ([typeString isEqualToString:@"GeometryCollection"]) {
        type = GeometryTypeGeometryCollection;
    }        
    return type;
}

@end
